package com.prs.crm.service.doc.impl;

import java.util.Collection;
import java.util.Date;

import com.prs.crm.context.ToolKits;
import com.prs.crm.dao.doc.IssueResumeDao;
import com.prs.crm.domain.doc.IssueResume;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.domain.hr.Resume;
import com.prs.crm.service.doc.IssueResumeService;
import com.prs.crm.service.hr.PersonService;
import com.prs.crm.service.hr.ResumeService;
import com.prs.crm.service.impl.BaseServiceImpl;

public class IssueResumeServiceImpl extends BaseServiceImpl<IssueResume,IssueResumeDao> implements IssueResumeService{
	private PersonService personService;
	private ResumeService resumeService;
	
	@Override
	public void submitIssueResume(Date issueStartTime, Date issueEndTime,
			String issueDocIds, String receivePersons) {
		// TODO Auto-generated method stub
		Collection<Person> persons = this.getPersonService().findPersons(ToolKits.convertStringAryToIntAry(receivePersons.split(",")));
		Collection<Resume> resumes = this.getResumeService().getResumeByIds(ToolKits.convertStringAryToIntAry(issueDocIds, ","));
		for(Resume resume:resumes) {
			for(Person person:persons) {
				IssueResume issue = new IssueResume();
				issue.setResume(resume);
				issue.setReceivePerson(person);
				issue.setStartTime(issueStartTime);
				issue.setEndTime(issueEndTime);
				
				this.getDao().save(issue);
			}
		}
	}

	public void setPersonService(PersonService personService) {
		this.personService = personService;
	}

	public PersonService getPersonService() {
		return personService;
	}

	public void setResumeService(ResumeService resumeService) {
		this.resumeService = resumeService;
	}

	public ResumeService getResumeService() {
		return resumeService;
	}

	@Override
	public Collection<IssueResume> getValidIssueResume(Person person) {
		// TODO Auto-generated method stub
		return this.getDao().getValidIssueResume(person);
	}

}
